package com.gxh.controller.user;

import com.gxh.entity.Category;
import com.gxh.result.Result;
import com.gxh.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userCategoryController")
@RequestMapping("/user/category")
@Slf4j
@Api(tags = "用户端-分类")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 查询所有分类
     * @return list
     */
    @RequestMapping("/list")
    @ApiOperation("用户端-分类列表")
    @Cacheable(value = "categoryCache",key = "'list'")
    public Result<List<Category>> list(){
        log.info("用户查询分类");
        List<Category> list = categoryService.list();
        return Result.success(list);
    }
}
